require('../css/commCss/normalize.css')
require('../css/commCss/reset.css')
require('../css/commCss/property.css')
require('../css/commCss/basic.css')

// 字体
require('../libs/fonts/iconfont.css')

require('../css/myUser.less')

//axios请求
const axios = require('axios')

//导入util
const util = require('../util/util')

// weui-插件库
require('weui')
const weui = require('weui.js')



// 文档加载事件
document.addEventListener('DOMContentLoaded',function(){
    /**
     * 0.底部导航
    */
     util.fixBottomNav('myUser')

    /**
     * 0.获取元素
     */
    const imgurl = document.querySelector("#imgurl")
    const nickname = document.querySelector("#nickname")//用户名
    const sign = document.querySelector("#sign")//个性签名
    const dynamicCount = document.querySelector("#dynamicCount")//个人动态条数
    const times = document.querySelector("#times")//分钟
    const calorie = document.querySelector("#calorie")//千卡
    const logOut = document.querySelector("#logOut")//退出登录
    

    /**
     * 1.Axios请求
     */
    axios.get('http://139.9.177.51:8099/users/mysportsBadge', {
        params: {
            userId: localStorage.getItem('userId')
        }
    }).then(function (res) {
        // console.log(res.data);

        if(res.data.status === 0){
            let user = res.data.data.user
            let sports = res.data.data.sports
            // console.log(user)
            
            //渲染
            if (user.imgurl) {
                // console.log(user.imgurl);
                // imgurl.src = "http://139.9.177.51:8099" + user.imgurl;
                imgurl.src = user.imgurl;
            }
            if (user.sign) {
                // console.log(user.sign);
                sign.textContent = user.sign;
            }
            nickname.textContent = user.nickname
        
            dynamicCount.textContent = res.data.data.dynamicCount
        
            times.textContent = sports.times
            calorie.textContent = Math.ceil(sports.calorie)
        }
    })


    /**
     * 2.退出登录
     * 点击logOut，退出登录，弹出提示窗，清空数据,跳转页面
     */
     logOut.addEventListener('click',function(){
        // console.log("1111");
        // 弹出提示窗
        weui.confirm("确认退出登录？",function(){

            // 
            // console.log("aaaa");
            // 清空本地存储
            localStorage.clear()
            // 跳转页面
            location.href = "./advert.js"
        })
     })

     /**
      * 3.跳转页面
      */
     //用户
     document.querySelector('#nameOne').addEventListener('click',function(){
         location.href = './myRevise.html'
     })

     //运动数据
     document.querySelector('#sportData').addEventListener('click',function(){
        location.href = './myData.html'
    })

     //运动徽章
     document.querySelector('#sportBadge').addEventListener('click',function(){
        location.href = './myBadge.html'
    })
})